#import "MainTabBarController.h"
#import "OmMomentsVC.h"
#import "OmHomeVC.h"
#import "OmMineVC.h"
#import "RootNavigationController.h"
#import "MsgViewController.h"
#import "UITabBar+CustomBadge.h"
#import "JLCardViewController.h"
#import "XYTabBar.h"
#import "ConversationListViewController.h"
@interface MainTabBarController ()<UITabBarControllerDelegate>
@property (nonatomic,strong) NSMutableArray * VCS;
@end
@implementation MainTabBarController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpTabBar];
    [self setUpAllChildViewController];
    self.tabBar.translucent = NO;
}
#pragma mark ————— 初始化TabBar —————
-(void)setUpTabBar{
    [self.tabBar setBackgroundColor:[UIColor whiteColor]];
    [self.tabBar setBackgroundImage:[UIImage new]];
}
#pragma mark - ——————— 初始化VC ————————
-(void)setUpAllChildViewController{
    _VCS = @[].mutableCopy;
    OmHomeVC *homeVC = [[OmHomeVC alloc]init];
    [self setupChildViewController:homeVC title:ASLocalizedString(@"首页")imageName:@"OmHome" seleceImageName:@"OmHome"];
    MsgViewController *msgVCC = [[MsgViewController alloc]init];
    [self setupChildViewController:msgVCC title:ASLocalizedString(@"信息")imageName:@"OmMessage" seleceImageName:@"OmMessage"];
    JLCardViewController *cardVC = [[JLCardViewController alloc]init];
    [self setupChildViewController:cardVC title:ASLocalizedString(@"心动") imageName:@"OmHeart" seleceImageName:@"OmHeart"];
    OmMomentsVC *momentsVC = [[OmMomentsVC alloc]init];
    [self setupChildViewController:momentsVC title:ASLocalizedString(@"新鲜事")imageName:@"OmTwitter" seleceImageName:@"OmTwitter"];
    OmMineVC *mineVC = [[OmMineVC alloc] init];
    [self setupChildViewController:mineVC title:ASLocalizedString(@"我的")imageName:@"OmMine" seleceImageName:@"OmMine"];
    self.viewControllers = _VCS;
}
-(void)setupChildViewController:(UIViewController*)controller title:(NSString *)title imageName:(NSString *)imageName seleceImageName:(NSString *)selectImageName{
    controller.title = title;
    controller.tabBarItem.title = [title isEqualToString:ASLocalizedString(@"心动")]?nil:title;
    controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:[title isEqualToString:ASLocalizedString(@"心动")] ? UIImageRenderingModeAlwaysOriginal : UIImageRenderingModeAlwaysTemplate];
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:KBlackColor,NSFontAttributeName:SYSTEMFONT(10.0f)} forState:UIControlStateNormal];
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:MainColor,NSFontAttributeName:SYSTEMFONT(10.0f)} forState:UIControlStateSelected];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:controller];
    nav.navigationBar.translucent = NO;
    nav.navigationBar.tintColor = [UIColor whiteColor];
    NSMutableDictionary *titleTextAttributes=[NSMutableDictionary dictionary];
    [titleTextAttributes setObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    nav.navigationBar.titleTextAttributes = titleTextAttributes;
    [nav.navigationBar setBackgroundImage:[OmHandyMethods imageFromColor:HexadecimalColor(@"FC7CB5") gradientToColor:HexadecimalColor(@"FCA7A1") frame:CGRectMake(0, 0, WINDOW_WIDTH, 64)] forBarMetrics:UIBarMetricsDefault];
    [_VCS addObject:nav];
}
@end
